package com.baizhi.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
        HttpSession session = request.getSession();
        Object login = session.getAttribute("login");
        System.out.println("login = " + login);
        if(login!=null) {
            return true;
        }else{
            response.sendRedirect(request.getContextPath()+"/login.jsp");
            return false;
        }
    }
}
